<template>
    <view class="goods-detail">
		<view class="top-content">
			<view class="img-box">
				<image class="img" :src="goodsMsg.image_url" mode=""></image>
			</view>
			<view class="text-content">
				<view class="title">
					{{goodsMsg.name}}
				</view>
				<text class="text">库存{{goodsMsg.stock}}件</text>
				<view class="price-text">
					<text class="red">￥{{goodsMsg.price}}</text>
					<text class="grey">官方价：{{goodsMsg.official_price}}</text>
				</view>
			</view>
		</view>
		<view class="red-box">
			<text>官方直充 闪电发货</text>
			<text>已售{{goodsMsg.sales}}件</text>
		</view>
		<view class="goods-text">
			<view class="title">
				<text class="iconfont iconzhuangshizhu"></text> 商品介绍
			</view>
			<view class="text" v-html="goodsMsg.description"></view>
		</view>
		<view class="link-btn" @click="linkpayment()">
			立即购买
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<van-toast id="van-toast" />
		<!-- #endif -->
    </view>
</template>
<script>
// #ifdef MP-WEIXIN
import Toast from '@/wxcomponents/vant-weapp/toast/toast.js';
// #endif
import { getproductData } from "@/api/getdata.js"
export default {
    name:"goodsDetail",
    data(){
        return {
			goodsMsg:{},
        }
	},
	onLoad(params) {
		this._initData(params.id);
		this.$setTopBar({title:"商品详情"});
	},
    methods:{
		async _initData(id){
			try{
				var _channel = this.$store.state.channel;
				uni.showLoading({title:"加载中"});
				let data = await getproductData({prod_name:id || 13 ,channel:_channel});
				this.goodsMsg = data[0];
				uni.hideLoading();
			}catch(e){
				uni.hideLoading();
				// #ifdef MP-WEIXIN
				Toast.fail(e.errMsg);
				// #endif
			}
		},
		linkpayment(){
			this.$store.commit("setgoodsData",this.goodsMsg);
			this.$router({
				url:"./payment"
			})
		}
    }
}
</script>
<style lang="scss" scoped>
  @import "./style/goodsdetail.scss";
</style>